@extends('manage.layout')

@section('content')
    <section class="content-header">
        <h1>
            添加案例
            <small>Preview</small>
        </h1>
        <ol class="breadcrumb">
            <li><a href="#"><i class="fa fa-dashboard"></i> Home</a></li>
            <li><a href="#">Case</a></li>
            <li class="active">Case Add</li>
        </ol>
    </section>

    <section class="content">
        <div class="row">
            <!-- left column -->
            <div class="col-md-12">
                <!-- general form elements -->
                <div class="box box-primary">
                    <div class="box-header with-border">
                        <h3 class="box-title">内容</h3>
                    </div>
                    <!-- /.box-header -->
                    <!-- form start -->
                    <form action="{{ url('caseCreate') }}" method="post" role="form" id="forminfo" style="max-width: 800px;" enctype="multipart/form-data">
                        {{--{{csrf_field()}}--}}
                        <input type="hidden" name="_token" value="{{ csrf_token() }}">
                        <div class="box-body">
                            <div class="form-group">
                                <label for="exampleInputPassword1">案例名称</label>
                                <input type="text" name="name" class="form-control" id="exampleInputPassword1" placeholder="Case Name" required>
                            </div>
                            <div class="form-group">
                                <label for="exampleInputEmail1">权重</label>
                                <input type="number" name="rank" class="form-control" placeholder="rank" value="0">
                            </div>

                            <div class="form-group">
                                <label for="exampleInputPassword1">所属行业</label>
                                <select name="industry" class="form-control">
                                    {{--<option>请选择</option>--}}
                                    @foreach($ind as $i)
                                        <option value="{{ $i['id'] }}">{{ $i['name'] }}</option>
                                    @endforeach
                                </select>
                                {{--<input type="text" name="industry" class="form-control" id="exampleInputPassword1" placeholder="Category Name">--}}
                            </div>
                            <div class="form-group">
                                <label for="exampleInputPassword1">应用场景</label>
                                <select name="scene" class="form-control">
                                    <option value="0">线上</option>
                                    <option value="1">线下</option>
                                </select>
                            </div>
                            <div class="form-group">
                                <label for="exampleInputPassword1">标签</label>
                                <select name="lable" class="form-control">
                                    <option value="0">普通</option>
                                    <option value="1">精品</option>
                                </select>
                            </div>
                            <div class="form-group">
                                <label for="exampleInputPassword1">所属类别</label>
                                <select name="grade" id="grade" class="form-control" onchange="change()">
                                    <option>请选择</option>
                                    @foreach($category as $c)
                                        <option value="{{ $c['id'] }}">{{ $c['name'] }}</option>
                                    @endforeach
                                </select>
                                <select name="classes" id="classes" class="form-control" onchange="second()">
                                    <option>请选择</option>
                                </select>
                                {{--<input type="text" name="category" class="form-control" id="exampleInputPassword1" placeholder="Category">--}}
                            </div>
                            <div class="form-group">
                                <label for="exampleInputPassword1">所属产品</label>
                                <select name="product_id" id="three" class="form-control" >
                                    <option>请选择</option>
                                    {{--@foreach($product as $pro)--}}
                                        {{--<option value="{{ $pro['id'] }}">{{ $pro['name'] }}</option>--}}
                                    {{--@endforeach--}}
                                </select>
                                {{--<input type="text" name="product_id" class="form-control" id="exampleInputPassword1" placeholder="Product">--}}
                            </div>
                            <div class="form-group">
                                <label for="exampleInputPassword1">设计师</label>
                                <select name="designer" class="form-control" required>
                                    {{--<option>请选择</option>--}}
                                    @foreach($designer as $des)
                                        <option value="{{ $des['id'] }}">{{ $des['name'] }}</option>
                                    @endforeach
                                </select>
                                {{--<label for="exampleInputPassword1">设计师</label>--}}
                                {{--<input type="text" name="designer" class="form-control" id="exampleInputPassword1" placeholder="Designer">--}}
                            </div>
                            <div class="form-group">
                                <label for="exampleInputPassword1">签约销售</label>
                                <input type="text" name="marketer" class="form-control" id="exampleInputPassword1" placeholder="Marketer">
                            </div>
                            <div class="form-group">
                                <label for="exampleInputPassword1">价格</label>
                                <input type="text" name="price" class="form-control" id="exampleInputPassword1" placeholder="Price">
                            </div>
                            <div class="form-group">
                                <label for="exampleInputPassword1">制作单位</label>
                                <input type="text" name="producer" class="form-control" id="exampleInputPassword1" placeholder="Make Company">
                            </div>
                            <div class="form-group">
                                <label for="exampleInputPassword1">制作时间</label>
                                <input type="text" name="make_time" class="form-control" id="datepicker" placeholder="Make Time">
                            </div>
                            <div class="form-group">
                                <label for="exampleInputPassword1">在线链接</label>
                                <input type="text" name="url" class="form-control" id="exampleInputPassword1" placeholder="URL">
                            </div>
                            <span id="attachment" style="display: none">case/attachment/</span>
                            <span id="picture" style="display: none">case/picture/</span>
                            <div class="form-group">
                                <label for="exampleInputPassword1">封面图</label>
                                <div id="container">
                                    <a id="selectfiles" href="javascript:void(0);" class='btn btn-primary'>选择文件</a>
                                    {{--<a id="postfiles" href="javascript:void(0);" class='btn btn-primary'>开始上传</a>--}}
                                </div>
                                <div class='clear container'>
                                    <!--<div id="dd" class="row"></div>-->
                                    <div id="ossfile"></div>
                                </div>
                                {{--<div class='clear container' >--}}
                                    {{--<div id="img"></div>--}}
                                {{--</div>--}}
                                <input type="hidden" name="cover" value="" id="getpath">
                            </div>
                            <div class="form-group">
                                <label for="exampleInputPassword1">关键字</label>
                                {{--<input type="text" name="url" class="form-control" id="exampleInputPassword1" placeholder="URL">--}}
                                <textarea name="keyword" class="form-control"  placeholder="keyword"></textarea>
                            </div>
                            <div class="form-group">
                                <label for="exampleInputPassword1">案例简介（网站描述）</label>
                                {{--<input type="text" name="url" class="form-control" id="exampleInputPassword1" placeholder="URL">--}}
                                <textarea name="brief" class="form-control"  placeholder="Brief"></textarea>
                            </div>
                            <div class="form-group">
                                <label for="exampleInputPassword1">案例内容</label>
                                {{--<input type="text" name="url" class="form-control" id="exampleInputPassword1" placeholder="URL">--}}
                                <textarea id="editor_id" name="content" class="form-control"  placeholder="Content"></textarea>
                            </div>
                            <div class="form-group">
                                <label for="exampleInputPassword1">图文编辑器</label>
                                {{--<input type="text" name="url" class="form-control" id="exampleInputPassword1" placeholder="URL">--}}
                                <textarea id="case_edit" name="case_edit" class="form-control"  placeholder="Content"></textarea>
                            </div>
                        </div>
                        <!-- /.box-body -->

                        <div class="box-footer">
                            <button type="submit" class="btn btn-primary">提交</button>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </section>
@stop
@section('script')
    <script type="text/javascript" src="/oss/upload_pic.js"></script>
    <script>

        //Date picker
        $('#datepicker').datepicker({
            autoclose: true,
            format: 'yyyy-mm-dd'
        });

        //类别二级联动
        function change() {
            var id = $("select[name='grade']").val();
            var data = {id:id};
            $.ajax({
                url: "case/classes/"+id,
                type: "get",
                data: data,
                dataType: "json",
                success: function(data) {
                    console.log(data);
                        $("#classes").empty();
                        var count = data.length;

                        var i = 0;
                        var b="";
                        for(i=0;i<count;i++){
                            b+="<option value='"+data[i].id+"'>"+data[i].name+"</option>";
                        }
                        $("#classes").append(b);
                    second();
                }
            });
        }

        //产品-三级联动
        function second() {
            var cate = $('#classes').val();
//            alert(cate);
            $.ajax({
                url: "case/three/"+cate,
                type: "get",
                data: {cate:cate},
                dataType: "json",
                success: function(data) {
                    console.log(data);
                    $("#three").empty();
                    var count = data.length;

                    var i = 0;
                    var b="";
                    for(i=0;i<count;i++){
                        b+="<option value='"+data[i].id+"'>"+data[i].name+"</option>";
                    }
                    $("#three").append(b);
                }
            });
        }

        //提交数据
        $(function() {
            var editor;
            KindEditor.ready(function(K) {
                editor = K.create('textarea[name="content"]', {
                    afterBlur: function () { this.sync(); },
                    resizeType : 1,
                    allowPreviewEmoticons : false,
                    allowImageUpload : false,
//                    syncType:form,
                    items : [
                        'fontname', 'fontsize', '|', 'forecolor', 'hilitecolor', 'bold', 'italic', 'underline',
                        'removeformat', '|', 'justifyleft', 'justifycenter', 'justifyright', 'insertorderedlist',
                        'insertunorderedlist', '|', 'emoticons',  'link']
                });


            });

            KindEditor.ready(function(K) {
                window.editor = K.create('textarea[name="case_edit"]', {
                    afterBlur: function () { this.sync(); }
                });
            });

            $("form").submit(function(event) {
                event.preventDefault();
                var url = $(this).attr("action");
//                var data = $("form").serialize();
                var formData = new FormData($( "#forminfo" )[0]);
//                console.log(data);
                $.ajax({
                    url: url,
                    type: "POST",
                    data: formData,
                    dataType: "json",
                    processData: false,
                    cache: false,
                    contentType: false,
                    success: function(res) {
                        console.log(res);
                        if(res.code == 100) {
                            window.location.href = "/caseList";
                            layer.msg(res.msg)
                        }
                        else {
                            layer.msg(res.msg)
                        }
                    }
                });
            });
        });

    </script>

@stop
